import { createWebHistory, createRouter } from 'vue-router'
//引入组件
import Home from '../views/Home/index.vue'
import Login from '../views/Login/index.vue'
import Layout from '../views/Layout/index.vue'
import Product from '../views/Product/index.vue'
import NProgress from 'nprogress' // 进度条
import 'nprogress/nprogress.css' // 这个样式必须引入
//配置路由规则
const routes = [
  {
    path: '/',
    component: Layout,
    children: [
      { path: 'home', component: Home, name: 'home' },
      { path: 'Product', component: Product, name: 'Product' }
    ]
  },
  { path: '/login', component: Login, name: 'login' }
]
//创建路由对象
const router = createRouter({
  history: createWebHistory(),
  routes
})
export default router

router.beforeEach((to, from, next) => {
  NProgress.start()
  next()
})
router.afterEach(() => {
  NProgress.done()
})
